@extends('layouts.admin-iframe-base')


@section('css')

@stop

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        用户管理
        <small>用户电站</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li class="active">首页</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <!-- Your Page Content Here -->
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">添加电站设备
                        <small>所属用户：{{$user->name}} &nbsp; 所属电站：{{$site->name}}</small>
                    </h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form class="form-horizontal" id="J-form" action="/admin/device/create-site-device" method="post">
                    <input name="site_id" type="hidden" value="{{$site->id}}">

                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">设备名称</label>

                            <div class="col-sm-10">
                                <input name="name" type="text" class="form-control" placeholder="设备名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">设备ID（与硬件一致）</label>

                            <div class="col-sm-10">
                                <input name="device_id" type="text" class="form-control" placeholder="设备名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">设备S/N号</label>

                            <div class="col-sm-10">
                                <input name="sn" type="text" class="form-control" placeholder="设备S/N号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">标准功率（单位：W)</label>

                            <div class="col-sm-10">
                                <input name="normal_power" type="text" class="form-control" placeholder="标准功率">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">实际功率（单位：W)</label>

                            <div class="col-sm-10">
                                <input name="actual_power" type="text" class="form-control" placeholder="实际功率">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属分组</label>

                            <div class="col-sm-10">
                                <select name="group_id" class="form-control J-select">
                                    <option selected="selected" value="-1">未选择</option>
                                    @foreach($site->groups as $g)
                                        <option value="{{$g->id}}">{{$g->name}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>

                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button type="submit" class="btn btn-info pull-right">添加</button>
                    </div>
                    <!-- /.box-footer -->
                </form>
            </div>

        </div>
    </div>

    <!-- /.box -->

</section>
<!-- /.content -->


@stop

@section('js')
    <script>

        $(function () {


            $('#J-form').ajaxForm({
                beforeSubmit: function () {
                    validator_info_clear($('#J-form'));
                },
                success: function (data) {
                    if (data.status == 1) {
                        alert('添加成功！');
                        window.location.href = '/admin/site/user-site-detail?user_id={{$user->id}}&id={{$site->id}}';
                    } else {
                        alert(data.error_msg);
                    }
                },
                error: function (xhr) {
                    validator_info_show($('#J-form'), xhr);
                }
            });

            $('.J-select').select2();
        });


    </script>
@stop